package p.ithorns.framework.redis.stream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import p.ithorns.framework.core.message.MsgPublisher;
import p.ithorns.framework.core.model.PubPacket;

/**
 * RedisStreamPublisher
 *
 * @author Ht.L
 * @date 2023-06-17 10:01
 * @since 1.0.0
 */
public class RedisStreamPublisher implements MsgPublisher {

    private final RedisStreamProducer producer;

    public RedisStreamPublisher(RedisStreamProducer producer) {
        this.producer = producer;
    }

    @Override
    public <T> void publish(PubPacket<T> msg) {
        producer.objRecord(msg.getType(), msg.getBody());
    }

    @Override
    public <T> void publish(String topic, T data) {
        publish(PubPacket.create(topic, data));
    }

}